/*
 * @Description: 添加标签
 * @Author: iamsmiling
 * @Date: 2021-06-15 11:02:34
 * @LastEditTime: 2021-06-15 14:47:24
 */
import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/pages/publish_square/children/publish_center/children/add_tag_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'package:credit_business_circle/domain/remote/topic/topic_tag_entity.dart';

class AddTagPage extends GetView<AddTagController> {
  const AddTagPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: R.color.ffffffff,
      appBar: AppBar(
        title: Text("添加标签"),
        elevation: .5,
      ),
      body: GetBuilder<AddTagController>(builder: (_) {
        return Container(
          margin: EdgeInsets.symmetric(horizontal: R.dimen.dp18),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                margin: EdgeInsets.symmetric(vertical: R.dimen.dp20),
                child: Text.rich(TextSpan(
                    text: "添加标签",
                    style: TextStyle(
                        fontSize: R.dimen.sp16,
                        color: R.color.ff333333,
                        fontWeight: FontWeight.w600),
                    children: [
                      TextSpan(
                          text: "（最多可选3个）",
                          style: TextStyle(
                              color: R.color.ff555555,
                              fontSize: R.dimen.sp13,
                              fontWeight: FontWeight.normal))
                    ])),
              ),
              Wrap(
                spacing: R.dimen.dp13,
                runSpacing: R.dimen.dp13,
                children: [
                  for (TopicTagEntity tag in controller.tags)
                    GestureDetector(
                      onTap: () => _.select(controller.tags.indexOf(tag)),
                      child: Container(
                        alignment: Alignment.center,
                        width: (R.dimen.width -
                                R.dimen.dp18 * 2 -
                                R.dimen.dp13 * 2) /
                            3.0001,
                        height: (R.dimen.width -
                                R.dimen.dp18 * 2 -
                                R.dimen.dp13 * 2) /
                            3.0001 *
                            33 /
                            105,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(R.dimen.sp5),
                            color:
                                controller.tags[controller.currentIndex] == tag
                                    ? null
                                    : R.color.fff5f5f5,
                            gradient:
                                controller.tags[controller.currentIndex] == tag
                                    ? LinearGradient(colors: [
                                        R.color.ff14ca94,
                                        R.color.ff1bbd8d
                                      ])
                                    : null),
                        child: Text(
                          "${tag.name}",
                          style: TextStyle(
                            fontSize: R.dimen.sp13,
                            color:
                                controller.tags[controller.currentIndex] == tag
                                    ? R.color.ffffffff
                                    : R.color.ff333333,
                          ),
                        ),
                      ),
                    )
                ],
              )
            ],
          ),
        );
      }),
      bottomNavigationBar: Container(
        height: kBottomNavigationBarHeight,
        margin: EdgeInsets.only(
            bottom: R.dimen.dp20, left: R.dimen.dp18, right: R.dimen.dp18),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Expanded(
              flex: 1,
              child: Container(
                margin: EdgeInsets.only(right: R.dimen.dp12),
                alignment: Alignment.center,
                padding: EdgeInsets.symmetric(vertical: R.dimen.dp13),
                decoration: BoxDecoration(
                    color: R.color.fff5f5f5,
                    borderRadius: BorderRadius.circular(R.dimen.dp5)),
                child: Text(
                  "新增标签",
                  style: TextStyle(
                      fontSize: R.dimen.sp14,
                      color: R.color.ff777777,
                      fontWeight: FontWeight.w600),
                ),
              ),
            ),
            Expanded(
              flex: 2,
              child: Container(
                alignment: Alignment.center,
                padding: EdgeInsets.symmetric(vertical: R.dimen.dp13),
                decoration: BoxDecoration(
                    gradient: LinearGradient(
                        colors: [R.color.ff14ca94, R.color.ff1bbd8d]),
                    borderRadius: BorderRadius.circular(R.dimen.dp5)),
                child: Text(
                  "确定",
                  style: TextStyle(
                      fontSize: R.dimen.sp14,
                      color: R.color.ffffffff,
                      fontWeight: FontWeight.w600),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
